//
//  AULoginViewController.swift
//  AwesomeULoginModule
//
//  Created by Miss_Special on 2018/4/28.
//

import UIKit
import AwesomeUBaseModule
import AwesomeUSharedModule

class AULoginViewController: UIViewController {
    
    @IBOutlet weak var loginViewLeftConstraint: NSLayoutConstraint!
    
    // 从xib中加载
    init() {
        let bundle = Bundle(for: type(of: self))
        super.init(nibName: "AULoginViewController", bundle: bundle)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    // 浅色状态栏
    override var preferredStatusBarStyle: UIStatusBarStyle {
        get {
            return .lightContent
        }
    }
}

// MARK: - Actions
extension AULoginViewController {
    
    // 显示登陆或注册
    @IBAction func showLoginOrRegister(_ sender: UIButton) {
        
        view.endEditing(true)
        
        sender.isSelected = !sender.isSelected
        loginViewLeftConstraint.constant = sender.isSelected ? -au_kScreenWidth : 0
        
        UIView.animate(withDuration: 0.5) {
            self.view.layoutIfNeeded()
        }
    }
    
    // 关闭事件
    @IBAction func closeButtonAction(_ sender: UIButton) {
        dismiss(animated: true) {
            AUSharedModule.sharedInstance.homeModule_needRefresh()
        }
    }
    
    // 登陆
    @IBAction func loginAction(_ sender: UIButton) {
        let userInfo = [
            "userID": "13511112222",
            "token": "13511112222"
        ]
        
        AUAccountManager.sharedInstance.updateAccount(dict: userInfo)
        
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
            self.dismiss(animated: true) {
                AUSharedModule.sharedInstance.homeModule_needRefresh()
            }
        }
    }
    
    // 注册
    @IBAction func registerAction(_ sender: UIButton) {
    }
}
